package ServerStuff;

import java.io.IOException;
import java.net.HttpURLConnection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import DataStorageClasses.Business;
import Database.DatabaseConnector;

@WebServlet("/GetBusinessProfileServlet")
public class GetBusinessProfileServlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		System.out.println("asdfsd");
		DatabaseConnector db = new DatabaseConnector();
		String busName = request.getParameter("business");
		
		Business profile = db.getProfile(busName);
	
		JSONObject result = new JSONObject();
		try {
			if (profile != null) {
				result.put("business", profile.getBusname());
				result.put("telephone", profile.getBusNum());
				result.put("cell", profile.getCell());
				result.put("city", profile.getCity());
				result.put("email", profile.getEmail());
				result.put("fax", profile.getFax());
				result.put("postal", profile.getPostal());
				result.put("province", profile.getProvince());
				result.put("address", profile.getStreetAd());
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		response.getWriter().print(result);
		response.setStatus(HttpURLConnection.HTTP_ACCEPTED);
	}

}
